package com.chenbei.common.handler.serializer;

import cn.hutool.core.util.StrUtil;
import com.fasterxml.jackson.core.JacksonException;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.JsonDeserializer;

import java.io.IOException;

public class DomainUrlDeserializer extends JsonDeserializer<String> {
    private final String DOMAIN;

    public DomainUrlDeserializer(String domain) {
        this.DOMAIN = domain;
    }

    @Override
    public String deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) throws IOException, JacksonException {
        String url = jsonParser.getValueAsString();
        if (StrUtil.isBlank(url)) {
            return null;
        }
        return url.replace(DOMAIN, "");
    }
}
